package com.neusoft.a312cxy.android18cxy.model;

import com.neusoft.a312cxy.android18cxy.Listener.PostListener;
import com.neusoft.a312cxy.android18cxy.service.MySelfService;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * Created by Young on 2017/10/20.
 */

public class MySelfModel {
    private Retrofit retrofit;
    private com.neusoft.a312cxy.android18cxy.service.MySelfService MySlefService;
    private static final String BASE_URL = "http://172.24.10.175/workout/api.php/";//主机地址

    public MySelfModel() {
        retrofit = new Retrofit.Builder()
                .baseUrl(BASE_URL)
                .addConverterFactory(GsonConverterFactory.create())
                .build();
    }

    public Call getMySelf(String id)
    {
        MySelfService MySelfService=retrofit.create(MySelfService.class);
        return MySelfService.getMySelf(id);
    }


    public Call getOrderlist(String userid, String vstate , int page)
    {
        MySelfService MySelfService=retrofit.create(MySelfService.class);
        return MySelfService.getorderlist(userid,vstate,page);
    }

    public Call getmyshaitu(String id, String related , String shaitu)
    {
        MySelfService MySelfService=retrofit.create(MySelfService.class);
        return MySelfService.getmyshaitu(id,related,shaitu);
    }

    public void  editTel(String userid,String tel ,String realname, String sex,String intro, final PostListener postListener){
        MySelfService myselfService=retrofit.create(MySelfService.class);
        Call<String> call = myselfService.editTel(userid,tel,realname,sex,intro);
        call.enqueue(new Callback<String>() {
            @Override
            public void onResponse(Call<String> call, Response<String> response) {
                if (response.isSuccessful()&& response.body()!=null){

                    postListener.onResponse(response.body());
                }
                else postListener.onFail("OnResponse fail");
            }

            @Override
            public void onFailure(Call<String> call, Throwable t) {
                postListener.onFail(t.toString());
            }
        });
    }
    public Call getmyguanzhu(String userid)
    {
        MySelfService MySelfService=retrofit.create(MySelfService.class);
        return MySelfService.myguanzhu(userid);
    }



}
